<?php
/**
 * Created by Engineer CuiLiwu.
 * Project: deal.
 * Date: 2018/6/28-10:28
 * License Hangzhou orce Technology Co., Ltd. Copyright © 2018
 */

namespace App\Http\Controllers\Web;

use App\Http\Controllers\Web\BaseController;
use Illuminate\Http\Request;

/**
 * 帮助中心，前台获取文章列表，文章详情
 * */
class HelperController extends BaseController
{
    protected $request;
    protected  $api_url = [
        'index' => ['get', 'helper'],
        'show' => ['get', 'helper/%d'],
        'cate' => ['get', 'helper/cate/%d'],
    ];

    public function __construct(Request $request)
    {
        $this->request = $request;
    }

    /**
     * 分类下文章列表
     * */
    public function index($id){
        $page = $this->request->get('page',1);
        $search_params['fid'] = $id;
        $params = [
            'search' => search_params($search_params),
            'searchJoin' => 'and',
            'page' => $page,
            'orderBy' => 'updated_at',
            'sortedBy' => 'desc',
        ];
        // 获取文章列表
        $ret = http_web($this->api_url['index'])->send($params);
        // 获取当前分类
        $cate = http_web($this->api_url['cate'],[$id])->send();
        $ret['data']['cate'] =$cate['data'] ;
//        dd($ret['data']);
        return view('web.help.help_list')->with($ret['data']);
    }
    
    /**
     * 文章详情
     * */
    public function show($id){
        $data = [];
        $ret  = http_web($this->api_url['show'],[$id])->send();
        $data['info'] = $ret['data'];
        // 获取当前分类
        $cate = http_web($this->api_url['cate'],[$ret['data']['fid']])->send();
        $data['cate'] =$cate['data'] ;

        return view('web.help.help')->with($data);
    }

}